package com.smartleanx.module.hrm.controller.admin.companysystem;

import com.smartleanx.framework.common.pojo.PageResult;
import com.smartleanx.module.hrm.controller.admin.companysystem.vo.*;
import com.smartleanx.module.hrm.controller.admin.companysystememployee.vo.CompanySystemEmployeePageReqVO;
import com.smartleanx.module.hrm.controller.admin.companysystemtype.vo.CompanySystemTypeTreeListRespVO;
import com.smartleanx.module.infra.api.file.dto.FileRefRespDTO;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.annotation.security.PermitAll;
import javax.validation.*;
import java.util.*;

import com.smartleanx.framework.common.pojo.CommonResult;
import static com.smartleanx.framework.common.pojo.CommonResult.success;

import com.smartleanx.module.hrm.service.companysystem.CompanySystemService;

@Tag(name = "管理后台 - 公司制度库")
@RestController
@RequestMapping("/hrm/company-system")
@Validated
public class CompanySystemController {

    @Resource
    private CompanySystemService companySystemService;

    @PostMapping("/create")
    @Operation(summary = "创建公司制度库")
    @PreAuthorize("@ss.hasPermission('hrm:company-system:create')")
    public CommonResult<Long> createCompanySystem(@Valid @RequestBody CompanySystemSaveReqVO createReqVO) {
        return success(companySystemService.createCompanySystem(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新公司制度库")
    @PreAuthorize("@ss.hasPermission('hrm:company-system:update')")
    public CommonResult<Boolean> updateCompanySystem(@Valid @RequestBody CompanySystemSaveReqVO updateReqVO) {
        companySystemService.updateCompanySystem(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除公司制度库")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('hrm:company-system:delete')")
    public CommonResult<Boolean> deleteCompanySystem(@RequestParam("id") Long id) {
        companySystemService.deleteCompanySystem(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得公司制度库")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('hrm:company-system:query')")
    public CommonResult<CompanySystemRespVO> getCompanySystem(@RequestParam("id") Long id) {
        return success( companySystemService.getCompanySystem(id));
    }

    @GetMapping("/page")
    @Operation(summary = "获得公司制度库分页")
    @PreAuthorize("@ss.hasPermission('hrm:company-system:query')")
    public CommonResult<PageResult<CompanySystemPageRespVo>> getCompanySystemPage(@Valid CompanySystemPageReqVO pageReqVO) {
        return success(companySystemService.getCompanySystemPage(pageReqVO));
    }

    @GetMapping("/getFileRefList")
    @Operation(summary = "获取文件预览地址（列表）")
    @PreAuthorize("@ss.hasPermission('hrm:company-system:query')")
    public CommonResult<List<CompanySystemFileRespVo>> getPreviewFileRef(@RequestParam("id") Long id){
        return success(companySystemService.getPreviewFileRef(id));
    }

    @GetMapping("/learnPage")
    @Operation(summary = "获得已学习未学习弹窗分页")
    @PreAuthorize("@ss.hasPermission('hrm:company-system:query')")
    public CommonResult<PageResult<CompanySystemLearnPageRespVo>> getLeanPage(@Valid CompanySystemEmployeePageReqVO reqVO){
        return success(companySystemService.getLeanPage(reqVO));

    }
    @GetMapping("/getEmployeeLearnPage")
    @Operation(summary = "员工端获取制度学习分页列表")
    @PreAuthorize("@ss.hasPermission('hrm:company-system:query')")
    public CommonResult<PageResult<EmployeeLearnPageRespVo>> getEmployeeLearnPage(@Valid CompanySystemPageReqVO pageReqVO){
        return success(companySystemService.getEmployeeLearnPage(pageReqVO));

    }



}
